package com.zhou.test.spring.secrity.controller;

import com.zhou.test.spring.secrity.model.Blog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author xianfeng
 * @date 2023/5/13 9:16
 */
@Slf4j
@Controller
public class LoginController {

    @GetMapping("/login")
    public String test2(Model model) {
        model.addAttribute("rm", true);
        model.addAttribute("remember", "remember-me");
        model.addAttribute("captchaEnabled", true);
        model.addAttribute("captcha", "captcha");
        model.addAttribute("un", "username");
        model.addAttribute("pwd", "password");
        return "login";
    }

    @PostMapping("/loginBody")
    @ResponseBody
    public String login(@RequestBody Map<String, String> body) {
        log.info("{}", body);
        return "login";
    }

    @PostMapping("/loginForm")
    @ResponseBody
    public String loginForm(@RequestParam Map<String, String> body) {
        log.info("{}", body);
        return "login";
    }

    @GetMapping("/index")
    public String index(Model model) {
        Blog blog = new Blog();
        blog.setId(1);
        blog.setName("yixin");
        blog.setPwd("123");
        model.addAttribute("blog", blog);
        return "index";
    }
}
